﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class Program
    {
        private System.ComponentModel.Composition.Hosting.CompositionContainer _container;

        [System.ComponentModel.Composition.Import(typeof(OAF.Base.IShell))]
        public OAF.Base.IShell shell;

        private Program()
        {
            //An aggregate catalog that combines multiple catalogs
            var catalog = new System.ComponentModel.Composition.Hosting.AggregateCatalog();
            //Adds all the parts found in the same assembly as the Program class
            catalog.Catalogs.Add(new System.ComponentModel.Composition.Hosting.AssemblyCatalog(typeof(Program).Assembly));
            //catalog.Catalogs.Add(new System.ComponentModel.Composition.Hosting.DirectoryCatalog(@"C:\Users\Ilyas\Desktop\CS\"));


            //Create the CompositionContainer with the parts in the catalog
            _container = new System.ComponentModel.Composition.Hosting.CompositionContainer(catalog);

            //Fill the imports of this object
            try
            {
                System.ComponentModel.Composition.Hosting.CompositionBatch batch = new System.ComponentModel.Composition.Hosting.CompositionBatch();
                foreach (var part in catalog.Parts)
                {
                    batch.AddPart(part.CreatePart());
                }

                this._container.Compose(batch);
            }
            catch (System.ComponentModel.Composition.CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }
        }


        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Program p = new Program();
            p.shell.Show();

            //Application.Run(new Form1());
        }
    }
}
